#!/bin/sh -
#
# build script for 1.0 - this only includes the lightweight API
# if a distribution name is given as an argument the build is placed
# in a subdirectory.
#
# Note: this script expects javadoc for jdk 1.2 to be in your path.
#

JDKPATH=/opt/jdk1.0.2   # JDK 1.0 location

base=$1
version=`echo $base | sed -e "s/\([0-9]\)\([0-9a-z]*\)/\1.\2/"`

WINDOWTITLE="Bouncy Castle Cryptography $version API Specification"
HEADER="<b>Bouncy Castle Cryptography $version</b>"
DOCTITLE="Bouncy Castle $version API Specification"

echo "making lightweight release"

if test "$base" != "" 
then
    mkdir lcrypto-jdk10-$base

    tar cf - index.html LICENSE.html CONTRIBUTORS.html releasenotes.html specifications.html src/org/bouncycastle/crypto src/org/bouncycastle/util src/org/bouncycastle/asn1 | (cd lcrypto-jdk10-$base; tar xf -)

    (2>&1 find lcrypto-jdk10-$base -name CVS -exec rm -rf \{\} \; ) > /dev/null
    rm -f lcrypto-jdk10-$base/src/org/bouncycastle/crypto/test/*
    rm -rf lcrypto-jdk10-$base/src/org/bouncycastle/crypto/examples
    rm -f lcrypto-jdk10-$base/src/org/bouncycastle/asn1/test/*

    (cd jdk1.0; tar cf - * | (cd ../lcrypto-jdk10-$base; cd src; tar xf -))

    (2>&1 find lcrypto-jdk10-$base -name CVS -exec rm -rf \{\} \; ) > /dev/null

    (cd lcrypto-jdk10-$base; mkdir docs; mkdir classes;

    (2>&1 javadoc -windowtitle "$WINDOWTITLE" -doctitle "$DOCTITLE" \
      -header "$HEADER" \
      -classpath classes \
      -d docs -sourcepath src \
    -group "Lightweight Crypto Packages" "org.bouncycastle.crypto*" \
    -group "ASN.1 Support Packages" "org.bouncycastle.asn1*" \
    -group "Math Support Packages" "org.bouncycastle.math*" \
    -group "Utility Packages" "org.bouncycastle.util*" \
    org.bouncycastle.asn1 \
    org.bouncycastle.asn1.cmp \
    org.bouncycastle.asn1.cms \
    org.bouncycastle.asn1.cryptopro \
    org.bouncycastle.asn1.esf \
    org.bouncycastle.asn1.esf \
    org.bouncycastle.asn1.ess \
    org.bouncycastle.asn1.misc \
    org.bouncycastle.asn1.mozilla \
    org.bouncycastle.asn1.nist \
    org.bouncycastle.asn1.ocsp \
    org.bouncycastle.asn1.oiw \
    org.bouncycastle.asn1.pkcs \
    org.bouncycastle.asn1.sec \
    org.bouncycastle.asn1.smime \
    org.bouncycastle.asn1.teletrust \
    org.bouncycastle.asn1.test \
    org.bouncycastle.asn1.tsp \
    org.bouncycastle.asn1.util \
    org.bouncycastle.asn1.x509 \
    org.bouncycastle.asn1.x9 \
    org.bouncycastle.math.ec \
    org.bouncycastle.crypto \
    org.bouncycastle.crypto.agreement \
    org.bouncycastle.crypto.digests \
    org.bouncycastle.crypto.encodings \
    org.bouncycastle.crypto.engines \
    org.bouncycastle.crypto.generators \
    org.bouncycastle.crypto.io \
    org.bouncycastle.crypto.macs \
    org.bouncycastle.crypto.modes \
    org.bouncycastle.crypto.paddings \
    org.bouncycastle.crypto.params \
    org.bouncycastle.crypto.signers \
    org.bouncycastle.crypto.test \
    org.bouncycastle.util.encoders \
    org.bouncycastle.util.test) > /dev/null \

    PATH=$JDKPATH/bin:$PATH
    export PATH
    JAVA_HOME=$JDKPATH
    export JAVA_HOME

    echo "compiling"

    (cd src; javac -d ../classes -classpath ../classes:../src:../jdk1.0:$JDKPATH/lib/classes.zip */*/*.java */*/*/*.java )
    (cd src; javac -d ../classes -classpath ../classes:../src:../jdk1.0:$JDKPATH/lib/classes.zip */*/[amu]*/*/*.java)
    (cd src; javac -d ../classes -classpath ../classes:../src:../jdk1.0:$JDKPATH/lib/classes.zip */*/c*/*/*.java)

    echo "lightweight regression test"
    java -classpath classes:$JDKPATH/lib/classes.zip org.bouncycastle.crypto.test.RegressionTest
    java -classpath classes:$JDKPATH/lib/classes.zip java.math.test.RegressionTest

    )
fi
